package xyz.mumuwei.youthcourseserver.exception;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author mumuwei
 * @date 2022/2/19
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BizException extends RuntimeException{
    private static final long serialVersionUID = 1L;

    protected String errorCode;
    protected String errorMsg;

    public BizException(BaseErrorInfo errorInfo) {
        super(errorInfo.getCode());
        this.errorCode = errorInfo.getCode();
        this.errorMsg = errorInfo.getMsg();
    }

    public BizException(BaseErrorInfo errorInfo, Throwable cause) {
        super(errorInfo.getCode(), cause);
        this.errorCode = errorInfo.getCode();
        this.errorMsg = errorInfo.getMsg();
    }

    public BizException(String msg) {
        super(msg);
        this.errorMsg = msg;
    }

    public BizException(String code, String msg, Throwable cause) {
        super(code, cause);
        this.errorCode = code;
        this.errorMsg = msg;
    }

    @Override
    public String getMessage() {
        return errorMsg;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
